package com.diaohw.platform.common.properties;

import lombok.Getter;
import lombok.Setter;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Component;

import java.util.Objects;

/**
 * @author 刁海文
 * @Remark 权限路由配置
 * @since 2023/6/29 20:43
 */
@Getter
@Setter
@Component
@Configuration
@EnableConfigurationProperties
@ConfigurationProperties(prefix = "platform.authorization")
public class AuthorizationProperties {

    /**
     * 包含的路径
     */
    private String[] pathPatterns;

    /**
     * 排除的路径
     */
    private String[] excludePathPatterns;

    /**
     * 是否统计在线用户
     */
    private boolean online;

    public String[] getPathPatterns() {
        if (pathPatterns == null) {
            return new String[]{"/**"};
        }
        return pathPatterns;
    }

    public String[] getExcludePathPatterns() {
        return Objects.requireNonNullElseGet(excludePathPatterns, () -> new String[0]);
    }

}
